package com.sto.stoapp.thread;

import android.app.ProgressDialog;
import android.content.Context;

import com.google.gson.Gson;
import com.sto.stoapp.activity.R;
import com.sto.stoapp.db.StoFilePreference;
import com.sto.stoapp.http.BaseMessage;
import com.sto.stoapp.util.UnifiedStaticType;

/**
 * 基类线程
 * 
 * @author Administrator
 * 
 */
public class BaseThread extends Thread {

	public Context context;

	private ProgressDialog pDialog;
    protected Gson gs=new Gson();

	protected static final int AVIATION_VERSION_PORT = 4024;

	/**
	 * 构造函数
	 * 
	 * @param context
	 */
	public BaseThread(Context context) {
		this.context = context;
	}

	/**
	 * 加载进度圈
	 */
	public void showDialog() {
		pDialog = new ProgressDialog(context);
		pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		pDialog.setTitle(R.string.prompt);
		pDialog.setMessage(context.getResources().getText(
				R.string.request_update));
		pDialog.setCancelable(false);
		pDialog.show();
	}

	/**
	 * 自定义消息体内容的滚动进度条
	 * 
	 * @param message
	 */
	public void showDialogByMessage(String message) {
		pDialog = new ProgressDialog(context);
		pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		pDialog.setTitle(R.string.prompt);
		pDialog.setMessage(message);
		pDialog.setCancelable(false);
		pDialog.show();
	}
	
	public void setProgressMessage(String message){
		if(pDialog!=null){
			pDialog.setMessage(message);
		}
	}

	/**
	 * 取消进度圈
	 */
	public void cancelDialog() {
		if (pDialog != null && pDialog.isShowing()) {
			pDialog.dismiss();
		}
	}

	protected int getPort() {
		if (BaseMessage.AVIATION_T_VERSION.equals(UnifiedStaticType.loginType)
				|| BaseMessage.AVIATION_A_VERSION
						.equals(UnifiedStaticType.loginType)) {
			return 4024;
		} else {
			return StoFilePreference.getInstance(context).getDataServicePort();
		}
	}
	public void setMessage(String message) {
		if(pDialog!=null) {
			pDialog.setMessage(message);
		}
	}

}
